/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.web.news;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.acq.entity.news.AcqNews;
import com.thinkgem.jeesite.modules.acq.service.news.AcqNewsService;

/**
 * 系统消息Controller
 * @author lj
 * @version 2018-06-28
 */
@Controller
@RequestMapping(value = "${adminPath}/acq/news/acqNews")
public class AcqNewsController extends BaseController {

	@Autowired
	private AcqNewsService acqNewsService;
	
	@ModelAttribute
	public AcqNews get(@RequestParam(required=false) String id) {
		AcqNews entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = acqNewsService.get(id);
		}
		if (entity == null){
			entity = new AcqNews();
		}
		return entity;
	}
	
	@RequiresPermissions("acq:news:acqNews:view")
	@RequestMapping(value = {"list", ""})
	public String list(AcqNews acqNews, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqNews> page = acqNewsService.findPage(new Page<AcqNews>(request, response), acqNews); 
		model.addAttribute("page", page);
		return "modules/acq/news/acqNewsList";
	}

	@RequiresPermissions("acq:news:acqNews:view")
	@RequestMapping(value = "form")
	public String form(AcqNews acqNews, Model model) {
		model.addAttribute("acqNews", acqNews);
		return "modules/acq/news/acqNewsForm";
	}

	@RequiresPermissions("acq:news:acqNews:edit")
	@RequestMapping(value = "save")
	public String save(AcqNews acqNews, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, acqNews)){
			return form(acqNews, model);
		}
		acqNewsService.save(acqNews);
		addMessage(redirectAttributes, "保存系统消息成功");
		return "redirect:"+Global.getAdminPath()+"/acq/news/acqNews/?repage";
	}
	
	@RequiresPermissions("acq:news:acqNews:edit")
	@RequestMapping(value = "delete")
	public String delete(AcqNews acqNews, RedirectAttributes redirectAttributes) {
		acqNewsService.delete(acqNews);
		addMessage(redirectAttributes, "删除系统消息成功");
		return "redirect:"+Global.getAdminPath()+"/acq/news/acqNews/?repage";
	}

}